package org.micode.libs.dao.helper;

import org.micode.common.exception.InvokeFailException;
import lombok.extern.slf4j.Slf4j;

import java.util.function.Function;

@Slf4j
public class DaoHelper {

    public static <T, R> R invoke(Function<T, R> method, T t) {
        try {
            return method.apply(t);
        } catch (Exception e) {
            log.error("Invoke() failed", e);
            throw new InvokeFailException(e.getMessage());
        }
    }

    public static <T, R> R invokeAndFailReturnNull(Function<T, R> method, T t) {
        try {
            return method.apply(t);
        } catch (Exception e) {
            log.error("Invoke() failed", e);
            return null;
        }
    }

}
